<template>
  <div>
    <div slot="header" class="clearfix">
      <span style="float: left; padding: 3px 0">key授权列表</span>
      <div style="float: right;">
        <el-button type="text" icon="el-icon-search">查询</el-button>
        <el-button type="text" icon="el-icon-delete">key回收</el-button>
      </div>
    </div>
    <com-table :tableData="tableData" url="" keyName="app" :has-data="hasData" :table-head-list="tableHeadList"
      :total-count="totalCount" :page-num="pageNum" :page-size="pageSize" :page-sizes="pageSizes"
      :table-loading="loading" :table-height="tableHeight" :is-show-select="true" :page-show="true" :handle-show="false"
      @setSearchHeight="setTableHeight" ref="comTable">
    </com-table>
  </div>
</template>

<script>
import ComTable from "../../components/table/comTable";
export default {
  components: {
    ComTable,
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 100],
      totalCount: 0,
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      hasData: true,
      loading: false, // 数据加载状态遮罩
      tableHeadList: [
        { columnComment: "授权用户单位名称", columnName: "name", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        { columnComment: "授权许可总数", olumnName: "state", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        { columnComment: "剩余可用许可", columnName: "creator", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
      ],
    }
  },
  created() {
    this.setTableHeight()
    this.getTableData()
  },
  methods: {
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 220;
    },
    getTableData() {
      let param = {
        data: {
          method: 'queryAuthorizationInfo',
          reqId: this.getUUID(),
          msg: ''
        }
      }
      this.$postForJson('vgmp/config/checkauthorization', param).then(res => {
        let data = res.data.data;
        if (!data.result) {
          this.$message.error('获取失败')
          return false
        }
        this.tableData = data.authInfoList
      })
    },
    getUUID() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
      })
    },
    search(){
      this.getTableData()
    }
  }
}
</script>

<style>
</style>